/**
 * Created by jacques on 2016/5/18.
 */

var iconMoves = [];
var IconMove = function(name,i,r,x,y,deg){
    this.t = 0;
    function run(i) {
        $(name).animate({
            "left": +x + r * Math.cos(i * deg * Math.PI / 180) + "px",
            "top": +y + r * Math.sin(i * deg * Math.PI / 180) + "px"
        }, 90);
    }
    this.auto_run = function() {
        this.t = setInterval(function () {
            i++;
            run(i);
        }, 100);
    };
    this.clearInterval = function(num){
        clearInterval(num);
    };

    $(name).hover(function () {
        for(var i = 0; i < iconMoves.length; i++){
            iconMoves[i].clearInterval(iconMoves[i].t);
        }
    }, function () {
        for(var i = 0; i < iconMoves.length; i++){
            iconMoves[i].auto_run();
        }
    });
};

$(document).ready(function () {
    //---page3 的图标圆周运动---

    var r = $('.dash-cir').width() / 2;
    var r2 = $('.icon').width() / 2;
    var x = r - r2;
    var x1 = r - 3*r2-10;
    var y = r - r2;
    var deg = 1;
    var n = 360;
    var i = -n / 4+35;
    var i2 = -n / 4-55;
    var i3 = -n / 4-120;
    var i4 = -n / 4+145;

    var iconMove = new IconMove('.icon1',i,r,x,y,deg);
    iconMove.auto_run();
    iconMoves.push(iconMove);

    var iconMove2 = new IconMove('.icon2',i2,r,x1,y,deg);
    iconMove2.auto_run();
    iconMoves.push(iconMove2);

    var iconMove3 = new IconMove('.icon3',i3,r,x1,y,deg);
    iconMove3.auto_run();
    iconMoves.push(iconMove3);

    var iconMove4 = new IconMove('.icon4',i4,r,x,y,deg);
    iconMove4.auto_run();
    iconMoves.push(iconMove4);

});